package service.Serviceimpl;

import Dao.NewsDao;
import domain.news;

import java.sql.SQLException;
import java.util.List;

public class newsService {
    NewsDao newsDao=new NewsDao();


    /*
    * 查询所有新闻
    * */
    public List<news> findAll(){
        String sql="SELECT * FROM news\n" +
                "WHERE 1=1\n" +
                "ORDER BY create_time DESC\n" +
                "LIMIT 0,10";

       return newsDao.findnewAll(sql);

    }


/*删除*/
public boolean delete(String id){
    String sql ="DELETE FROM news WHERE n_id=?";
    try {
        return newsDao.delete(sql,id);
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return false;
}
/*新增*/
    public boolean addnews(String title,String body) {
    String sql="INSERT INTO news (title,n_body,create_time) VALUES(?,?,?)";
        return newsDao.addnews(sql,title,body);
    }
    /*模糊查询*/
    public List<news> cx(String title) throws SQLException {

        String sql="SELECT  * FROM news WHERE  title LIKE  ? ";
        return newsDao.cx(sql,title);
    }
/*修改*/
    public boolean xgnews(String title, String body,String id) {
        String sql="UPDATE news SET title=？,n_body=? WHERE n_id=?";
        return newsDao.xg(sql,title,body,id);
    }
}
